package com.hzhc.controller.wxapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.YwOrderService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.YwOrderVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/26 10:46
 * @description WxApiYwOrderSgjController
 */
@RestController
@RequestMapping("/app")
@RequiredArgsConstructor
public class WxApiYwOrderSgjController extends BaseController {

    private final YwOrderService ywOrderService;

    @Value("${cms.targetUrl}")
    private String targetUrl;
    /**
     * wx 散改集业务新增
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/addSgjOrder")
    @SysTemLog(operModul = "商务管理-新增散改集业务",operType = "新增",operDesc = "新增散改集业务",modular="PC")
    public ResultUtil<T> addSgjOrder(HttpServletRequest request,@RequestBody YwOrderVo vo){
        UserDto user = TokenUtil.getUser(request);
        vo.setUserId(user.getId());
        vo.setUserName(user.getRealname());
        return ywOrderService.addSgjOrder(vo,targetUrl);
    }

    /**
     * wx 散改集列表list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getAllSgjList")
    public ResultUtil<List<YwOrderVo>> getAllSgjList(HttpServletRequest request, @RequestBody YwOrderVo vo){
        Page<YwOrderVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<YwOrderVo> list = ywOrderService.getAllSgjList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * wx 散改集 修改
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/updateSgjOrder")
    @SysTemLog(operModul = "商务管理-修改散改集业务",operType = "修改",operDesc = "修改散改集业务",modular="PC")
    public ResultUtil<T> updateSgjOrder(HttpServletRequest request, @RequestBody YwOrderVo vo){
        UserDto user = TokenUtil.getUser(request);
        vo.setUpdateUserId(user.getId());
        vo.setUpdateUserName(user.getRealname());
        vo.setUpdateTime(LocalDateTime.now());
        return ywOrderService.updateSgjOrder(vo);
    }

    /**
     * wx 散改集 删除
     * @param vo
     * @return
     */
    @PostMapping("/deleteSgjOrder")
    @SysTemLog(operModul = "商务管理-删除散改集业务",operType = "删除",operDesc = "删除散改集业务",modular="PC")
    public ResultUtil<T> deleteSgjOrder(@RequestBody YwOrderVo vo){
        return ywOrderService.deleteSgjOrder(vo.getId());
    }


}
